// UrlRewriter - A .NET URL Rewriter module
// Version 1.7
//
// Copyright 2006 Intelligencia
// Copyright 2006 Seth Yates
// 

using System;

namespace Intelligencia.UrlRewriter.Actions
{
	/// <summary>
	/// Sets the Location.
	/// </summary>
	public abstract class SetLocationAction : IRewriteAction
	{
		/// <summary>
		/// Default constructor.
		/// </summary>
		/// <param name="location">The location (pattern) to set.</param>
		public SetLocationAction(string location)
		{
			_location = location;
		}

		/// <summary>
		/// The location to set.  This can include replacements referencing the matched pattern,
		/// for example $1, $2, ... $n and ${group} as well as ${ServerVariable} and mapping, e.g., 
		/// ${MapName:$1}.
		/// </summary>
		public string Location
		{
			get
			{
				return _location;
			}
			set
			{
				_location = value;
			}
		}

		/// <summary>
		/// Executes the action.
		/// </summary>
		/// <param name="context">The rewriting context.</param>
		public virtual void Execute(RewriteContext context)
		{
			context.Location = context.ResolveLocation(context.Expand(Location));
		}

		/// <summary>
		/// The Processing directive.
		/// </summary>
		public virtual RewriteProcessing Processing
		{
			get
			{
				return RewriteProcessing.ContinueProcessing;
			}
		}

		private string _location;
	}
}
